﻿using System.Collections.Generic;
using HRC.Library.DBAccessLayer.Parameters;
using HRC.Library.EntityLibrary.EntityOperations;
using Lehnet.BusinessLayer.Interfaces;

namespace Lehnet.BusinessLayer
{
    public class PersonelBusiness : IPersonelBusiness
    {
        public List<Models.Personel> LoadAll()
        {
            return EntityManager.LoadAll<Models.Personel>();
        }

        public void SaveOrUpdate(Models.Personel personel)
        {
            if (personel.Id == 0)
                EntityManager.Insert(personel);
            else
                EntityManager.Update(personel);
        }

        public Models.Personel LoadPersonelById(int personelId)
        {
            return EntityManager.Load<Models.Personel>(" where Id=" + personelId.ToString());
        }

        public void Delete(int personelId)
        {
            EntityManager.Delete<Models.Personel>(new HRCParameter("Id", personelId, HRCParameterType.INT));
        }

        public Models.Personel Login(Models.Personel personel)
        {
            //TODO@baris: parametre olmalı burada kesinlikle.
           return EntityManager.Load<Models.Personel>(string.Format(" where KullaniciAdi='{0}' and Sifre='{1}'",personel.KullaniciAdi,personel.Sifre));
        }
    }
}
